<?php
class IndexController extends Zendvn_Controller_Action
{
	//Mang tham so nhan duoc o moi Action
	protected $_arrParam;
	
	//Duong dan cua Controller
	protected $_currentController;
	
	//Duong dan cua Action chinh
	protected $_actionMain;
	
	//Thong so phan trang
	protected $_paginator = array(
		'itemCountPerPage' => 2,
	);
	
	protected $_namespace;
	
	public function init()
	{	
		//Mang tham so nhan duoc o moi Action
		$this->_arrParam = $this->_request->getParams();
		
		//Duong dan cua Controller
		$this->_currentController = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller'];
		
		//Duong dan cua Action chinh		
		$this->_actionMain = '/' . $this->_arrParam['module'] . '/' . $this->_arrParam['controller']	. '/index';	

							 
		$this->_paginator['currentPage'] = $this->_request->getParam('page', 1);
		$this->_arrParam['paginator'] = $this->_paginator;
		
		//Truyen ra view
		$this->view->arrParam = $this->_arrParam;
		$this->view->currentController = $this->_currentController;
		$this->view->actionMain = $this->_actionMain;
		
		$template_path = TEMPLATE_PATH . "/public/default";
		$this->loadTemplate($template_path, 'template.ini', 'template');
		
		$fileCss = array();
		$fileCss[] = '/style.css';
		foreach ($fileCss as $key => $css) {
			$this->view->headLink()->appendStylesheet($this->view->cssUrl . $css,'screen');
		}
	}
		
	public function indexAction()
	{	
		
	}
	
	public function catAction()
	{
		$content = new Default_Model_Cat($this->_arrParam);
		$this->view->content = $content->getItems();
		
		$totalItem = $content->getTotal();
		$paginator = new Zendvn_Paginator();
		$currentUrl = $this->view->baseUrl('catalogue/' . $this->_arrParam['cid']. '-' .$this->_arrParam['ctitle']);
		$this->view->panigator = $paginator->createPaginator($currentUrl, $totalItem, $this->_paginator['currentPage'], $this->_paginator['itemCountPerPage']);
	}
	
	public function subAction()
	{
		$content = new Default_Model_Sub($this->_arrParam);
		$this->view->content = $content->getItems();
		$totalItem = $content->getTotal();
		$paginator = new Zendvn_Paginator();
		$currentUrl = $this->view->baseUrl('catalogue/' . $this->_arrParam['cid']. '-' .$this->_arrParam['ctitle'] . '/' .$this->_arrParam['sid'] . '-' .$this->_arrParam['stitle']);
		$this->view->panigator = $paginator->createPaginator($currentUrl, $totalItem, $this->_paginator['currentPage'], $this->_paginator['itemCountPerPage']);
	}
}